#!/usr/bin/env python3
#-*-encoding:utf-8-*-

import os
from collections import deque 

#清空控制台
def clear():
    print("\033c",end="")


def person_is_seller(name):  #检查姓名是否以m结尾 
    return name[-1] == 'm'

clear()  #清屏
graph = {}
graph["you"] = ["alice","bob","claire"]
graph["bob"] = ["anuj","peggy"]
graph["alice"] = ["peggy"]
graph["claire"] = ["thom","jonny"]
graph["anuj"] = []
graph["peggy"] = []
graph["thom"]=[]
graph["jonny"] = ["rtm"]
graph["rtm"] = []

def search(name):
    search_queue = deque() #创建一个队列
    search_queue += graph[name] #将你的邻居加入到这个搜索队列
    searched = []
    while search_queue: #队列不为空
        person = search_queue.popleft() 
        if not person in searched: #当这个人没有检查过时
            if person_is_seller(person):
                print(person,"is a mango seller!")
                return True
            else :
                search_queue += graph[person] #不是芒果销售商，将这个人的朋友加入搜索队列
                searched.append(person)
    return False


search("you")
